package cn.nbt.busManage.dao.mapper;

import cn.nbt.busManage.model.dto.DriverDto;
import cn.nbt.busManage.model.entity.Driver;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DriverMapper {
    /**
     * 根据信息查询司机
     *
     * @param query 查询信息（名称）
     * @return 司机信息
     */
    @Select("select * from driver where driver.driver_name like '%${query}%'")
    List<Driver> findByName(String query);

    /**
     * 根据信息查询司机
     *
     * @param driverId 查询信息（id）
     * @return 司机信息
     */
    @Select("select * from driver where  driver.id = #{driverId}")
    Driver findByDriverId(@Param("driverId") Integer driverId);

    /**
     * 返回所有司机信息
     *
     * @return 司机信息
     */
    @Select("select * from driver")
    List<Driver> findAllDriver();

    /**
     * 根据信息增加司机
     * @param driver 增加信息
     */
    @Insert("insert into driver(driver_name,birthday,address,cell) " +
            "values(#{driver.driverName}, #{driver.birthday}, #{driver.address}, #{driver.cell}) ")
    void save(Driver driver);

    /**
     * 根据信息更新司机
     * @return 信息
     */
    @Update("update driver set driver.driver_name=#{ndriver.driverName},driver.birthday=#{ndriver.birthday},driver.address=#{ndriver.address}, driver.cell=#{ndriver.cell} where driver.id = #{ndriver.driverId}")
    List<Driver> updateDriver(Driver ndriver);

    /**
     * 根据信息删除司机
     * @param driverId 删除信息
     */
    @Delete("delete from driver where driver.id = #{driverId}")
    void deleteDriver(@Param("driverId") Integer driverId);

    /**
     * 根据信息查询司机
     * @param driverName 查询信息（名称）
     * @return 司机信息
     */
    @Select("select * from driver where driver.driver_name = #{driverName}")
    Driver findByDName(@Param("driverName") String driverName);
}